
local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseObject());
local GeneralTool=_G.CommonOHOH.load.GeneralTool();

local guiClass = require(script.gui)
local UIManager= _G.ClientOHOH.load.UIManager()

local Goods_Cfg=CommonOHOH.config.Goods
local PetTool=CommonOHOH.load.PetTool()
local CellClass=require(script.Parent.Cell)

function M.new(self,...)
	return M(self,...);
end;


function M.ctor(self,eggCfg,att,eggluckCtrl,player,gui)
    self.cfg=eggCfg
    self.ctrl=eggluckCtrl
    self.att=att
    self.player=player
    self.DataBase=self.player:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent());
    self.EggId=self.cfg.id
    local eggName=""
    if  self.cfg.name>0 then --蛋存在名字
        eggName=_G.LanguageHelper:GetText(self.cfg.name)
    end
    local probability=GeneralTool.GetProbabilityShowPercent(self.cfg.probability)
    self.CellList={}

    for k,v in pairs(self.cfg.petIds) do
        local petId=PetTool.GetPetId(v)
        local guid=self:GetGuid(k,petId)
        local cell=CellClass.new(petId,guid,nil,self.DataBase)
        cell:SetProbability(probability[k])

        table.insert(self.CellList,cell )
    end


    local good1Cfg=Goods_Cfg[self.cfg.info[1][1]]
    local good2Cfg=Goods_Cfg[self.cfg.info[2][1]]
    local price1=good1Cfg.price
    local price2=good2Cfg.price

    local count1=self.cfg.info[1][2]
    local count2=self.cfg.info[2][2]

    local ui_id="BuyEggGui_"..self.EggId

    self.gui=UIManager:CreateUI(ui_id,guiClass,gui,eggName,price1,price2,count1,count2,self.CellList)

    self.gui.Pay1Event:Connect(function()

        -- print("------Pay1Event------good1Cfg------",self.EggId,good1Cfg.id)

        self.player.RobuxBuyEvent:Action(good1Cfg.id)
       
    end)

    self.gui.Pay2Event:Connect(function()

        -- print("------Pay2Event------good1Cfg------",self.EggId,good2Cfg.id)

        self.player.RobuxBuyEvent:Action(good2Cfg.id)
    end)
    
end;

function M.GetGuid(self,index,petId)
    return  self.EggId.."_"..index
end


function M.Show(self)

    self.gui:Show()

end


function M.Hide(self)

    for _,cell in pairs(self.CellList) do
        cell:ClearMouseEnter(nil)
    end

    self.gui:Hide()
end

function M.dtor(self)
	M.super.dtor(self);
end;




return M;
